/**
 * This file shows how to create a custom component and register that within an Angular application.
 *
 * Get the base component class by referencing Formio.Components.components map.
 */
import {Components,Templates} from 'formiojs';

const FieldComponent = (Components as any).components.field;

/**
 * Here we will derive from the base component which all Form.io form components derive from.
 *
 * @param component
 * @param options
 * @param data
 * @constructor
 */
class SelectCompany extends (FieldComponent as any) {
  public checks: Array<Array<any>>;
  constructor(component: any, options: any, data: any) {
    super(component, options, data);
    this.checks = [];
  }

  public static editForm = {};
  static schema() {
    return FieldComponent.schema({
      type: 'SelectCompany',
      numRows: 1,
      numCols: 1
    });
  }


  static builderInfo = {
    title: 'SelectCompany',
    group: 'basic',
    icon: 'fa fa-table',
    weight: 70,
    documentation: 'http://help.form.io/userguide/#table',
    schema: SelectCompany.schema()
  }


  public render(children: any) {
    return super.render(this.renderTemplate('selectCompany', {
      foo: 1238
    }));
  }

  /**
   * After the html string has been mounted into the dom, the dom element is returned here. Use refs to find specific
   * elements to attach functionality to.
   *
   * @param element
   * @returns {Promise}
   */
  attach(element: any) {
    // Allow basic component functionality to attach like field logic and tooltips.
    return super.attach(element);
  }

  /**
   * Get the value of the component from the dom elements.
   *
   * @returns {Array}
   */
  getValue() {
    return '111';
  }

  /**
   * Set the value of the component into the dom elements.
   *
   * @param value
   * @returns {boolean}
   */
  setValue(value: any) {
    console.log(value)
  }
}

SelectCompany.editForm = (...args: any) => {
  return FieldComponent.editForm(...args);
};

export default {
  SelectCompany
}
